export class ResponseDto<T> {
  readonly code: number;
  readonly message: string;
  readonly data: T extends null ? null : T | undefined;
  readonly timestamp: string;
  readonly success: boolean;

  constructor(code: number, message: string, data: T, success: boolean) {
    this.code = code;
    this.message = message;
    this.data = data as T extends null ? null : T;
    this.timestamp = new Date().toISOString();
    this.success = success;
  }

  static success<T>(data: T) {
    return new ResponseDto(200, 'success', data, true);
  }

  static error(message: string, code = 400) {
    return new ResponseDto(code, message, null, false);
  }
}
